import Vue from 'vue'
import Router from 'vue-router'
// import store from '@/store'
import index from '@/views/index.vue'
import allGame from '@/views/business/gameData/allGame.vue'
import t1 from '@/views/business/gameData/realtime.vue'
import t2 from '@/views/business/gameData/retained.vue'
import t3 from '@/views/business/gameData/pay.vue'
import report from '@/views/business/kpi/kpi.vue'
import kpi from '@/views/business/kpi/kpi.vue'
import login from '@/views/business/user/login.vue'
import NotFoundComponent  from '@/views/404.vue'

Vue.use(Router)

const router = new Router({
  mode:'history',
  routes: [
    {
      path: '/',
      redirect: '/all/statistics',
      component: index,
      children: [
        { path: 'all/:id', component: allGame },
        { path: 'report', component: report },
        { path: 'kpi', component: kpi }
      ]
    },
    {
      path: '/game/:id',
      component: index,
      children: [
        { path: 'realtime', component: t1 },
        { path: 'retained', component: t2 },
        { path: 'pay', component: t3 }
      ]
    },
    {
      path: '/login',
      meta: {
        noLogin: true,
      },
      component: login
    },
    {
      path: '*',
      component: NotFoundComponent}
  ]
});
router.beforeEach((to, from, next) => {
  // console.log(to,$.param( to.query ),window.location.href)
  if(to.meta.noLogin||sessionStorage.user){
    next();
  }else {
    next({
      path: '/login',
      query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
    });
  }
});
export default router;
